﻿package view.components.mainMenu 
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import org.casalib.display.CasaMovieClip;
	import view.components.IMainComponent;
	import view.components.utils.UIEvent;
	
	import gs.TweenLite;
	import gs.easing.Circ;
	
	/**
	 * ...
	 * @author Lobanov
	 */
	public class MainMenu extends MovieClip implements IMainComponent
	{
		
		//item of menu
		private var _itemMenuArr:Array;
		private var menuContainer:CasaMovieClip;
		
		public function MainMenu($xmlData:XMLList) 
		{			
			_itemMenuArr = [];
			menuContainer = new CasaMovieClip();
			this.addChild(menuContainer);
			
			var shiftMenuItem:Number = 0;
			
			for each (var page:XML in $xmlData.page) {
				var menuItem:MenuItem = new MenuItem(page.@title, page.@route, page.@mod);
				menuItem.addEventListener(MenuItem.DEEPLINK_INFO, deeplinkInfoHandler);
				_itemMenuArr.push( {id:page.@mod , instance:menuItem } );
				menuContainer.addChild(menuItem);
				
				menuItem.x += shiftMenuItem;
				shiftMenuItem += menuItem.menuWidth + 40;
			}
			
			menuContainer.x -= shiftMenuItem/ 2 - 20;
		}
		
		public function setPosition($width:Number, $height:Number):void {
			this.x = $width / 2;
			this.y = 110;
		}		
		
		private function deeplinkInfoHandler(e:UIEvent):void 
		{
			ApplicationFacade.getInstance().sendNotification(ApplicationFacade.CHANGE_MODULE, e.data as Array);
		}
		
		public function set activeMenu($module):void {
			
		}
	}

}